package com.cgs.query.service.impl

import com.cgs.query.config.JpaCustomProperties
import com.cgs.query.config.JpaCustomPropertiesAware
import com.cgs.query.config.RunnerJdbcTemplateAware
import com.cgs.query.handler.UserInfoHolder
import com.cgs.query.handler.UserInfoHolderAware
import com.cgs.query.service.IQueryTagService
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.jdbc.core.RowMapper
import org.springframework.stereotype.Service

@Service
class QueryTagServiceImpl : IQueryTagService, UserInfoHolderAware, RunnerJdbcTemplateAware, JpaCustomPropertiesAware {

    private lateinit var userInfoHolder: UserInfoHolder
    private lateinit var jdbcTemplate: JdbcTemplate
    private lateinit var jpaCustomProperties: JpaCustomProperties

    override fun findAll(): List<String> {
        return jdbcTemplate.query(jpaCustomProperties.findTags, RowMapper<String> { rs, _ ->
            if (rs != null) {
                return@RowMapper rs.getString(1)
            }
            return@RowMapper null
        })
    }

    override fun setUserInfoHolder(userInfoHolder: UserInfoHolder) {
        this.userInfoHolder = userInfoHolder
    }

    override fun setRunnerJdbcTemplate(jdbcTemplate: JdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate
    }

    override fun setJpaCustomProperties(jpaCustomProperties: JpaCustomProperties) {
        this.jpaCustomProperties = jpaCustomProperties
    }

}